public class Test04 {
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;
        int res = 0;
        int[] presum = new int[len + 1];
        presum[0] = 0;
        for (int i = 1; i < len; i++) {
            presum[i] = presum[i-1] + nums[i-1];
        }
        for (int i = 1; i < len; i++) {
            for (int j = 0; j < i; j++) {
                if(presum[i] - presum[j] == k){
                    res++;
                }
            }
        }
        return res;
    }
}
